Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIU-3011 - UserInformation in UserDetails to display profile picture. #2618

Merged
merged 13 commits into from
Jan 31, 2024

Conversation

Terala-Priyanka
Copy link
Contributor

@Terala-Priyanka Terala-Priyanka commented Jan 25, 2024

Purpose

UIU-3011 - User Record View with Profile Picture
UIU-3024 - User Record View with profile picture thumbnail

Approach

This story implements changes to display user profile picture on user detail under "user information" accordion.

When profile pictures are enabled, and user has a profile picture, his/her profile picture is displayed. The source of the picture could be a public url or an id from the database. When in case of id(uuid), profile picture is fetched from API.

When profile pictures are enabled, and user does not have a profile picture, a thumbnail image will be displayed.

When profile pictures configuration is not enabled, then user detail will remain the same. The above-described changes will not reflect.

TODOS and Open Questions

Screencast

when profile pictures are enabled and user has permissions to view profile pictures-
https://github.com/folio-org/ui-users/assets/104053200/8cc64dee-ff01-4bab-ad4c-1495d1cc7ffa

Pre-Merge Checklist

Before merging this PR, please go through the following list and take appropriate actions.

  • I've added appropriate record to the CHANGELOG.md
  • Does this PR meet or exceed the expected quality standards?
    • Code coverage on new code is 80% or greater
    • Duplications on new code is 3% or less
    • There are no major code smells or security issues
  • Does this introduce breaking changes?
    • If any API-related changes - okapi interfaces and permissions are reviewed/changed correspondingly
    • There are no breaking changes in this PR.

If there are breaking changes, please STOP and consider the following:

  • What other modules will these changes impact?
  • Do JIRAs exist to update the impacted modules?
    • If not, please create them
    • Do they contain the appropriate level of detail? Which endpoints/schemas changed, etc.
    • Do they have all they appropriate links to blocked/related issues?
  • Are the JIRAs under active development?
    • If not, contact the project's PO and make sure they're aware of the urgency.
  • Do PRs exist for these changes?
    • If so, have they been approved?

Ideally all of the PRs involved in breaking changes would be merged in the same day to avoid breaking the folio-testing environment. Communication is paramount if that is to be achieved, especially as the number of intermodule and inter-team dependencies increase.

While it's helpful for reviewers to help identify potential problems, ensuring that it's safe to merge is ultimately the responsibility of the PR assignee.

@Terala-Priyanka Terala-Priyanka marked this pull request as draft January 25, 2024 08:45
@Terala-Priyanka Terala-Priyanka self-assigned this Jan 25, 2024
@Terala-Priyanka Terala-Priyanka marked this pull request as ready for review January 25, 2024 10:08
@Terala-Priyanka Terala-Priyanka requested a review from a team January 25, 2024 10:28
*/
const isProfilePictureLinkAURL = !isAValidUUID(profilePictureLink);
const profilePicturesEnabled = Boolean(settings.length) && settings[0].enabled;
const hasViewProfilePicPerm = stripes.hasPerm('ui-users.profile-pictures.view');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Picture instead of Pic to ensure consistency with other places and make it easier to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in order not to make the variable name long, I have preferred pic to picture here. But if it seems to affect the readability, I can update it as per your suggestion.

const hasProfilePicture = (settings.length && settings[0].value === 'true');
const renderProfilePic = () => {
const profilePictureSrc = isProfilePictureLinkAURL ? profilePictureLink : 'data:;base64,' + profilePictureData;
const imgSrc = isLoading || isFetching || !hasProfilePicture ? ProfilePicThumbnail : profilePictureSrc;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please select only the loading you need. Two are excessive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will retain "isFetching" instead of isLoading as an image can take time to fetch based on its size.

import { USER_TYPE_FIELD } from '../../../constants';
import ProfilePicThumbnail from '../../../../icons/ProfilePicThumbnail.png';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please name the picture, starting with a lowercase letter.

Comment on lines 14 to 19
jest.mock('@folio/stripes/core', () => ({
...jest.requireActual('@folio/stripes/core'),
useStripes: jest.fn(() => ({
hasPerm: () => true,
})),
}));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useStripes is already mocked in stripesCore.mock.js.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanedup

const useProfilePicture = ({ profilePictureId }, options = {}) => {
const ky = useOkapiKy();
const [namespace] = useNamespace({ key: 'get-profile-picture-of-a-user' });
const DEFAULT_DATA = {};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable is eccessive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment on lines 12 to 16
jest.mock('@folio/stripes/core', () => ({
...jest.requireActual('@folio/stripes/core'),
useNamespace: jest.fn(() => ['test']),
useOkapiKy: jest.fn(),
}));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are already mocked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleaned up several things

Comment on lines 20 to 25
// eslint-disable-next-line react/prop-types
const wrapper = ({ children }) => (
<QueryClientProvider client={queryClient}>
{children}
</QueryClientProvider>
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an eslint warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed to clear it after updating code.

@Dmytro-Melnyshyn Dmytro-Melnyshyn requested a review from a team January 29, 2024 17:54
Copy link

@Terala-Priyanka Terala-Priyanka requested a review from a team January 30, 2024 12:38
@Terala-Priyanka Terala-Priyanka merged commit f2425b2 into master Jan 31, 2024
5 checks passed
@Terala-Priyanka Terala-Priyanka deleted the UIU-3011 branch January 31, 2024 04:41
records: 'configs',
path: 'configurations/entries?query=(module==USERS and configName==profile_pictures)',
path: 'users/configurations/entry',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Terala-Priyanka, it appears this endpoint is added in users interface 16.1 but this query isn't fenced off by something that checks for that interface. This means the Q release either needed to drop support for 16 and bump its major version to 11, or this work should have been properly fenced off by interface version checks. Do you know which is correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants